import codecs

import requests
import hashlib


class zaker:
    def gen_webcode(self,_udid, _appid, _v, _version):
        """
        生成ZAKER应用的_webcode参数

        返回:
        生成的_webcode参数（20字符长度）
        """
        # 组合初始字符串
        initial_str = f"{_udid},,{_appid},{_v},{_version}".lower()
        # 连续2次MD5哈希
        result = initial_str
        for _ in range(3):
            result = hashlib.md5(result.encode()).hexdigest().lower()

            # 截断为20字符
        return result[:20]

    def md5(self,str):
        return hashlib.md5(str.encode("utf-8")).hexdigest()
    def gen_flag(self,key, appid, udid, version, timestamp):
        parr = key + appid + udid + version + timestamp
        jiami1 =self.md5(parr)
        jiami2 = self.md5(jiami1)
        return jiami2

headers = {
    "Host": "search.myzaker.com",
    "sec-ch-ua": "\"Not)A;Brand\";v=\"8\", \"Chromium\";v=\"138\", \"Android WebView\";v=\"138\"",
    "sec-ch-ua-mobile": "?1",
    "sec-ch-ua-platform": "\"Android\"",
    "Upgrade-Insecure-Requests": "1",
    "User-Agent": "Mozilla/5.0 (Linux; Android 13; 23013RK75C Build/TKQ1.220905.001; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/138.0.7204.179 Mobile Safari/537.36 ZAKER/9.1.5",
    "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
    "appinfo": "zaker 9.1.5 androidphone",
    "X-Requested-With": "com.myzaker.ZAKER_Phone",
    "Sec-Fetch-Site": "none",
    "Sec-Fetch-Mode": "navigate",
    "Sec-Fetch-User": "?1",
    "Sec-Fetch-Dest": "document",
    "Accept-Language": "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7"
}
url = "https://search.myzaker.com/api/"
zakerr = zaker()
_udid="1fb67af59b5699a6"
_appid="AndroidPhone"
_v="9.1.5"
_version="9.08"
_time="1754548972"
_webcode=zakerr.gen_webcode(_udid,_appid , _v, _version)
print(_webcode)
key="WvT6dYtChFRdb7yKsearch"
_flag = zakerr.gen_flag(key, _appid, _udid, _version, _time)
params = {
    "_webcode": _webcode,
    "_flag": _flag,
    "_os": "13_23013RK75C",
    "sign_arg": "search|_appid,_udid,_uid,_version,keyword",
    "app_ids": "660,310000,13,9,4,11542,5,7,3,8,10530,14,11581,14733",
    "_os_name": "23013RK75C",
    "_mcode": "782ECE9C",
    "_only_read": "N",
    "_clicode": "drkjeSEfcYDX1teOXihrCj2XzcFRNfVX8%2BYz4c8F97ou09PFuxwXRz5MiGDDPUNGhem0wpj6%2FrZjDz2db1S7FvanFsXVXzuSqDN0%2F9H5fXQboq5tdRLZNTtTWglt14Ow2up6UUUAOroimS1HlUPRnt%2FCQ4I%2BuQaYbMO3tBgfzppDreyPYJ3gJetESX4Iz9g%2F",
    "appType": "normal",
    "_v": _v,
    "_udid": _udid,
    "_appid": _appid,
    "_dev": "39",
    "keyword": "特朗普",
    "full_arg": "_udid",
    "_version": _version,
    "_time": _time,
    "_brand": "Redmi"
}
response = requests.get(url, headers=headers, params=params)

decoded_text = codecs.decode(response.text, 'unicode_escape')
print(decoded_text)